package com.yz.crm.web.resolver;

import javax.servlet.http.HttpServletRequest;

import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebArgumentResolver;
import org.springframework.web.context.request.NativeWebRequest;

import com.yz.crm.passport.model.SessionUser;
import com.yz.util.WebUtils;

/**
 * 登录用户处理
 * */
public class SessionUserResolver implements WebArgumentResolver {
	
	@Override
	public Object resolveArgument(MethodParameter mp, NativeWebRequest request)
			throws Exception {
		
		if (isNeedGetSessionUser(mp)){
			return WebUtils.getLoginUser((request.getNativeRequest(HttpServletRequest.class)));
		}
		
		return UNRESOLVED;
	}

	/**
	 * 是否需要获取客户端信息
	 * */
	private boolean isNeedGetSessionUser(MethodParameter mp) {

		return mp.getGenericParameterType() == SessionUser.class ;
	}

}
